package com.zhaoyue.study.io.bio;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 2017/1/3
 * Time: 14:56
 * To change this template use File | Settings | File Templates.
 */
public class TimeServer {
    public static void main(String[] args) throws IOException{

        int port = 8080;
        ServerSocket serverSocket = null;
        try{
            serverSocket = new ServerSocket(port);
            System.out.println("the time server start on port :" + port);
            Socket socket = null;
            while (true){
                socket = serverSocket.accept();//监听客户端接入
                System.out.println("客户端有接入");
                new Thread(new TimeServerHandler(socket)).start();//开启线程处理请求
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if(serverSocket!=null){
                serverSocket.close();
            }
        }

    }
}
